package com.beiming.libra.controller;

import java.util.List;
import javax.annotation.Resource;
import javax.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.beiming.libra.domain.AuthRoleRelation;
import com.beiming.libra.domain.dto.requestdto.AuthRoleRelationRequestDTO;
import com.beiming.libra.domain.dto.requestdto.CommonIdRequestDTO;
import com.beiming.libra.service.AuthRoleRelationService;
/**
 * 角色和权限
 * @author weibo
 *
 */
@Controller
@Slf4j
@RequestMapping(value = "/authRoleRelation")
public class AuthRoleRelationController {

  private static final Logger LOGGER = LoggerFactory.getLogger(AuthRoleRelationController.class);
  @Resource
  private AuthRoleRelationService authRoleRelationService;

  /**
   * 更新和新增合并在一起 添加角色和权限的关系
   */
  @RequestMapping(value = "insertAuthRoleRelation", method = RequestMethod.POST)
  @ResponseBody
  public void insertAndUpdateAuthRoleRelation(
      @RequestBody @Valid AuthRoleRelationRequestDTO authRoleRelationRequestDTO) {
    authRoleRelationService.insertAuthRoleRelation(authRoleRelationRequestDTO);
  }

  /**
   * 删除角色和权限信息
   */
  @RequestMapping(value = "deleteAuthRoleRelation", method = RequestMethod.POST)
  @ResponseBody
  public void deleteAuthRoleRelation(@RequestBody @Valid CommonIdRequestDTO commonIdRequestDTO) {
    authRoleRelationService.deleteAuthRoleRelation(commonIdRequestDTO.getId());
  }

  /**
   * 获取角色和权限信息
   */
  @RequestMapping(value = "getAuthRoleRelation", method = RequestMethod.POST)
  @ResponseBody
  public List<AuthRoleRelation> getAuthRoleRelation(
      @RequestBody @Valid CommonIdRequestDTO commonIdRequestDTO) {
    return authRoleRelationService.getAuthRoleRelation(commonIdRequestDTO.getId());
  }
}
